/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ships.core.icc;

import java.util.Arrays;

/**
 *
 * @author fqhuy
 */
public class icProfileHeader {

    public static class icTag {

        public  icTag() {
            
        }

        icTagSignature sig;            /* The tag signature */

        int offset = 0;         /* Start of tag relative to
         * start of header, Spec
         * Clause 5 */

        int size = 0;           /* Size in bytes */

    }

    public static class icProfileID {

        private byte ID8[] = new byte[16];
        private short ID16[] = new short[8];
        private int ID32[] = new int[4];

        public icProfileID(byte[] arr) {
            this.ID8 = arr;
            //this.ID32 = IccUtil.byteArrayToIntArray(arr);
        }


        public static int length = 16;

        @Override
        public boolean equals(Object obj){
            return java.util.Arrays.equals(ID8,( (icProfileID) obj).getID8());
        }

        @Override
        public int hashCode() {
            int hash = 7;
            hash = 17 * hash + Arrays.hashCode(this.ID8);
            return hash;
        }

        /**
         * @return the ID8
         */
        public byte[] getID8() {
            return ID8;
        }

        /**
         * @param ID8 the ID8 to set
         */
        public void setID8(byte[] ID8) {
            this.ID8 = ID8;
        }

        /**
         * @return the ID16
         */
        public short[] getID16() {
            return ID16;
        }

        /**
         * @param ID16 the ID16 to set
         */
        public void setID16(short[] ID16) {
            this.ID16 = ID16;
        }

        /**
         * @return the ID32
         */
        public int[] getID32() {
            return ID32;
        }

        /**
         * @param ID32 the ID32 to set
         */
        public void setID32(int[] ID32) {
            this.ID32 = ID32;
        }
    }

    public static class icXYZNumber {

        public icXYZNumber() {
            X=Y=Z=0;
        }

        int X;
        int Y;
        int Z;
    }

    public enum icTagSignature {

        icSigAToB0Tag(0x41324230), /* 'A2B0' */
        icSigAToB1Tag(0x41324231), /* 'A2B1' */
        icSigAToB2Tag(0x41324232), /* 'A2B2' */
        icSigBlueColorantTag(0x6258595A), /* 'bXYZ' */
        icSigBlueMatrixColumnTag(0x6258595A), /* 'bXYZ' */
        icSigBlueTRCTag(0x62545243), /* 'bTRC' */
        icSigBToA0Tag(0x42324130), /* 'B2A0' */
        icSigBToA1Tag(0x42324131), /* 'B2A1' */
        icSigBToA2Tag(0x42324132), /* 'B2A2' */
        icSigCalibrationDateTimeTag(0x63616C74), /* 'calt' */
        icSigCharTargetTag(0x74617267), /* 'targ' */
        icSigChromaticAdaptationTag(0x63686164), /* 'chad' */
        icSigChromaticityTag(0x6368726D), /* 'chrm' */
        icSigColorantOrderTag(0x636C726F), /* 'clro' */
        icSigColorantTableTag(0x636C7274), /* 'clrt' */
        icSigColorantTableOutTag(0x636C6F74), /* 'clot' */
        icSigColorimetricIntentImageStateTag(0x63696973), /* 'ciis' */
        icSigCopyrightTag(0x63707274), /* 'cprt' */
        icSigCrdInfoTag(0x63726469), /* 'crdi' Removed in V4 */
        icSigDataTag(0x64617461), /* 'data' Removed in V4 */
        icSigDateTimeTag(0x6474696D), /* 'dtim' Removed in V4 */
        icSigDeviceMfgDescTag(0x646D6E64), /* 'dmnd' */
        icSigDeviceModelDescTag(0x646D6464), /* 'dmdd' */
        icSigDeviceSettingsTag(0x64657673), /* 'devs' Removed in V4 */
        icSigDToB0Tag(0x44324230), /* 'D2B0' */
        icSigDToB1Tag(0x44324231), /* 'D2B1' */
        icSigDToB2Tag(0x44324232), /* 'D2B2' */
        icSigDToB3Tag(0x44324233), /* 'D2B3' */
        icSigBToD0Tag(0x42324430), /* 'B2D0' */
        icSigBToD1Tag(0x42324431), /* 'B2D1' */
        icSigBToD2Tag(0x42324432), /* 'B2D2' */
        icSigBToD3Tag(0x42324433), /* 'B2D3' */
        icSigGamutTag(0x67616D74), /* 'gamt' */
        icSigGrayTRCTag(0x6b545243), /* 'kTRC' */
        icSigGreenColorantTag(0x6758595A), /* 'gXYZ' */
        icSigGreenMatrixColumnTag(0x6758595A), /* 'gXYZ' */
        icSigGreenTRCTag(0x67545243), /* 'gTRC' */
        icSigLuminanceTag(0x6C756d69), /* 'lumi' */
        icSigMeasurementTag(0x6D656173), /* 'meas' */
        icSigMediaBlackPointTag(0x626B7074), /* 'bkpt' */
        icSigMediaWhitePointTag(0x77747074), /* 'wtpt' */
        icSigMetaDataTag(0x6D657461), /* 'meta' */
        //#if 0
        icSigNamedColorTag(0x6E636f6C), /* 'ncol' OBSOLETE, use ncl2 */
        //#endif
        icSigNamedColor2Tag(0x6E636C32), /* 'ncl2' */
        icSigOutputResponseTag(0x72657370), /* 'resp' */
        icSigPerceptualRenderingIntentGamutTag(0x72696730), /* 'rig0' */
        icSigPreview0Tag(0x70726530), /* 'pre0' */
        icSigPreview1Tag(0x70726531), /* 'pre1' */
        icSigPreview2Tag(0x70726532), /* 'pre2' */
        icSigPrintConditionTag(0x7074636e), /* 'ptcn' */
        icSigProfileDescriptionTag(0x64657363), /* 'desc' */
        icSigProfileSequenceDescTag(0x70736571), /* 'pseq' */
        icSigProfileSequceIdTag(0x70736964), /* 'psid' */
        icSigPs2CRD0Tag(0x70736430), /* 'psd0' Removed in V4 */
        icSigPs2CRD1Tag(0x70736431), /* 'psd1' Removed in V4 */
        icSigPs2CRD2Tag(0x70736432), /* 'psd2' Removed in V4 */
        icSigPs2CRD3Tag(0x70736433), /* 'psd3' Removed in V4 */
        icSigPs2CSATag(0x70733273), /* 'ps2s' Removed in V4 */
        icSigPs2RenderingIntentTag(0x70733269), /* 'ps2i' Removed in V4 */
        icSigRedColorantTag(0x7258595A), /* 'rXYZ' */
        icSigRedMatrixColumnTag(0x7258595A), /* 'rXYZ' */
        icSigRedTRCTag(0x72545243), /* 'rTRC' */
        icSigSaturationRenderingIntentGamutTag(0x72696732), /* 'rig2' */
        icSigScreeningDescTag(0x73637264), /* 'scrd' Removed in V4 */
        icSigScreeningTag(0x7363726E), /* 'scrn' Removed in V4 */
        icSigTechnologyTag(0x74656368), /* 'tech' */
        icSigUcrBgTag(0x62666420), /* 'bfd ' Removed in V4 */
        icSigViewingCondDescTag(0x76756564), /* 'vued' */
        icSigViewingConditionsTag(0x76696577);  /* 'view' */

        private int value;

        private icTagSignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
        public static icTagSignature fromInt(int val) {

            for (icTagSignature i : icTagSignature.values()) {
                if (i.getValue() == val) {
                    return i;
                }
            }
            return null;
        }
    }

    public enum icColorSpaceSignature {

        icSigXYZData(0x58595A20), /* 'XYZ ' */
        icSigLabData(0x4C616220), /* 'Lab ' */
        icSigLuvData(0x4C757620), /* 'Luv ' */
        icSigYCbCrData(0x59436272), /* 'YCbr' */
        icSigYxyData(0x59787920), /* 'Yxy ' */
        icSigRgbData(0x52474220), /* 'RGB ' */
        icSigGrayData(0x47524159), /* 'GRAY' */
        icSigHsvData(0x48535620), /* 'HSV ' */
        icSigHlsData(0x484C5320), /* 'HLS ' */
        icSigCmykData(0x434D594B), /* 'CMYK' */
        icSigCmyData(0x434D5920), /* 'CMY ' */
        icSigMCH2Data(0x32434C52), /* '2CLR' */
        icSigMCH3Data(0x33434C52), /* '3CLR' */
        icSigMCH4Data(0x34434C52), /* '4CLR' */
        icSigMCH5Data(0x35434C52), /* '5CLR' */
        icSigMCH6Data(0x36434C52), /* '6CLR' */
        icSigMCH7Data(0x37434C52), /* '7CLR' */
        icSigMCH8Data(0x38434C52), /* '8CLR' */
        icSigMCH9Data(0x39434C52), /* '9CLR' */
        icSigMCHAData(0x41434C52), /* 'ACLR' */
        icSigMCHBData(0x42434C52), /* 'BCLR' */
        icSigMCHCData(0x43434C52), /* 'CCLR' */
        icSigMCHDData(0x44434C52), /* 'DCLR' */
        icSigMCHEData(0x45434C52), /* 'ECLR' */
        icSigMCHFData(0x46434C52), /* 'FCLR' */
        icSigNamedData(0x6e6d636c), /* 'nmcl' */
        icSig2colorData(0x32434C52), /* '2CLR' */
        icSig3colorData(0x33434C52), /* '3CLR' */
        icSig4colorData(0x34434C52), /* '4CLR' */
        icSig5colorData(0x35434C52), /* '5CLR' */
        icSig6colorData(0x36434C52), /* '6CLR' */
        icSig7colorData(0x37434C52), /* '7CLR' */
        icSig8colorData(0x38434C52), /* '8CLR' */
        icSig9colorData(0x39434C52), /* '9CLR' */
        icSig10colorData(0x41434C52), /* 'ACLR' */
        icSig11colorData(0x42434C52), /* 'BCLR' */
        icSig12colorData(0x43434C52), /* 'CCLR' */
        icSig13colorData(0x44434C52), /* 'DCLR' */
        icSig14colorData(0x45434C52), /* 'ECLR' */
        icSig15colorData(0x46434C52);  /* 'FCLR' */

        private int value;

        private icColorSpaceSignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }

        public static icColorSpaceSignature fromInt(int val) {

            for (icColorSpaceSignature i : icColorSpaceSignature.values()) {
                if (i.getValue() == val) {
                    return i;
                }
            }
            return null;
        }
    }

    public enum icProfileClassSignature {

        icSigInputClass(0x73636E72), /* 'scnr' */
        icSigDisplayClass(0x6D6E7472), /* 'mntr' */
        icSigOutputClass(0x70727472), /* 'prtr' */
        icSigLinkClass(0x6C696E6B), /* 'link' */
        icSigAbstractClass(0x61627374), /* 'abst' */
        icSigColorSpaceClass(0x73706163), /* 'spac' */
        icSigNamedColorClass(0x6e6d636c);  /* 'nmcl' */

        private int value;

        private icProfileClassSignature(int value) {
            this.value = value;

        }

        public int getValue() {
            return this.value;

            //this.values()
        }

        public static icProfileClassSignature fromInt(int val) {

            for (icProfileClassSignature i : icProfileClassSignature.values()) {
                if (i.getValue() == val) {
                    return i;
                }
            }
            return null;
        }
    }

    public enum icPlatformSignature {

        icSigMacintosh(0x4150504C), /* 'APPL' */
        icSigMicrosoft(0x4D534654), /* 'MSFT' */
        icSigSolaris(0x53554E57), /* 'SUNW' */
        icSigSGI(0x53474920), /* 'SGI ' */
        icSigTaligent(0x54474E54), /* 'TGNT' */
        icSigUnkownPlatform(0x00000000);
        private int value;

        private icPlatformSignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
        public static icPlatformSignature fromInt(int val) {

            for (icPlatformSignature  i : icPlatformSignature.values()) {
                if (i.getValue() == val) {
                    return i;
                }
            }
            return null;
        }
    }

    public enum icTagTypeSignature {

        icSigChromaticityType(0x6368726D), /* 'chrm' */
        icSigColorantOrderType(0x636C726F), /* 'clro' */
        icSigColorantTableType(0x636C7274), /* 'clrt' */
        icSigCrdInfoType(0x63726469), /* 'crdi' Removed in V4 */
        icSigCurveType(0x63757276), /* 'curv' */
        icSigDataType(0x64617461), /* 'data' */
        icSigDictType(0x64696374), /* 'dict' */
        icSigDateTimeType(0x6474696D), /* 'dtim' */
        icSigDeviceSettingsType(0x64657673), /* 'devs' Removed in V4 */
        icSigLut16Type(0x6d667432), /* 'mft2' */
        icSigLut8Type(0x6d667431), /* 'mft1' */
        icSigLutAtoBType(0x6d414220), /* 'mAB ' */
        icSigLutBtoAType(0x6d424120), /* 'mBA ' */
        icSigMeasurementType(0x6D656173), /* 'meas' */
        icSigMultiLocalizedUnicodeType(0x6D6C7563), /* 'mluc' */
        icSigMultiProcessElementType(0x6D706574), /* 'mpet' */
        //#if 0
        icSigNamedColorType(0x6E636f6C), /* 'ncol' OBSOLETE, use ncl2 */
        //#endif
        icSigNamedColor2Type(0x6E636C32), /* 'ncl2' */
        icSigParametricCurveType(0x70617261), /* 'para' */
        icSigProfileSequenceDescType(0x70736571), /* 'pseq' */
        icSigProfileSequceIdType(0x70736964), /* 'psid' */
        icSigResponseCurveSet16Type(0x72637332), /* 'rcs2' */
        icSigS15Fixed16ArrayType(0x73663332), /* 'sf32' */
        icSigScreeningType(0x7363726E), /* 'scrn' Removed in V4 */
        icSigSignatureType(0x73696720), /* 'sig ' */
        icSigTextType(0x74657874), /* 'text' */
        icSigTextDescriptionType(0x64657363), /* 'desc' Removed in V4 */
        icSigU16Fixed16ArrayType(0x75663332), /* 'uf32' */
        icSigUcrBgType(0x62666420), /* 'bfd ' Removed in V4 */
        icSigUInt16ArrayType(0x75693136), /* 'ui16' */
        icSigUInt32ArrayType(0x75693332), /* 'ui32' */
        icSigUInt64ArrayType(0x75693634), /* 'ui64' */
        icSigUInt8ArrayType(0x75693038), /* 'ui08' */
        icSigViewingConditionsType(0x76696577), /* 'view' */
        icSigXYZType(0x58595A20), /* 'XYZ ' */
        icSigXYZArrayType(0x58595A20), /* 'XYZ ' */
        icMaxEnumType(0xFFFFFFFF);
        private int value;

        private icTagTypeSignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public enum icTechnologySignature {

        icSigDigitalCamera(0x6463616D), /* 'dcam' */
        icSigFilmScanner(0x6673636E), /* 'fscn' */
        icSigReflectiveScanner(0x7273636E), /* 'rscn' */
        icSigInkJetPrinter(0x696A6574), /* 'ijet' */
        icSigThermalWaxPrinter(0x74776178), /* 'twax' */
        icSigElectrophotographicPrinter(0x6570686F), /* 'epho' */
        icSigElectrostaticPrinter(0x65737461), /* 'esta' */
        icSigDyeSublimationPrinter(0x64737562), /* 'dsub' */
        icSigPhotographicPaperPrinter(0x7270686F), /* 'rpho' */
        icSigFilmWriter(0x6670726E), /* 'fprn' */
        icSigVideoMonitor(0x7669646D), /* 'vidm' */
        icSigVideoCamera(0x76696463), /* 'vidc' */
        icSigProjectionTelevision(0x706A7476), /* 'pjtv' */
        icSigCRTDisplay(0x43525420), /* 'CRT ' */
        icSigPMDisplay(0x504D4420), /* 'PMD ' */
        icSigAMDisplay(0x414D4420), /* 'AMD ' */
        icSigPhotoCD(0x4B504344), /* 'KPCD' */
        icSigPhotoImageSetter(0x696D6773), /* 'imgs' */
        icSigGravure(0x67726176), /* 'grav' */
        icSigOffsetLithography(0x6F666673), /* 'offs' */
        icSigSilkscreen(0x73696C6B), /* 'silk' */
        icSigFlexography(0x666C6578), /* 'flex' */
        icSigMotionPictureFilmScanner(0x6D706673), /* 'mpfs' */
        icSigMotionPictureFilmRecorder(0x6D706672), /* 'mpfr' */
        icSigDigitalMotionPictureCamera(0x646D7063), /* 'dmpc' */
        icSigDigitalCinemaProjector(0x64636A70);  /* 'dcpj' */

        private int value;

        private icTechnologySignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public enum icCmmSignature {

        icSigAdobe(0x41444245), /* 'ADBE' */
        icSigApple(0x6170706C), /* 'appl' */
        icSigColorGear(0x43434D53), /* 'CCMS' */
        icSigColorGearLite(0x5543434D), /* 'UCCM' */
        icSigFujiFilm(0x46462020), /* 'FF  ' */
        icSigHarlequinRIP(0x48434d4d), /* 'HCMM' */
        icSigArgyllCMS(0x6172676C), /* 'argl' */
        icSigLogoSync(0x44676f53), /* 'LgoS' */
        icSigHeidelberg(0x48444d20), /* 'HDM ' */
        icSigLittleCMS(0x6C636d73), /* 'lcms' */
        icSigKodak(0x4b434d53), /* 'KCMS' */
        icSigKonicaMinolta(0x4d434d44), /* 'MCML' */
        icSigMutoh(0x5349474E), /* 'SIGN' */
        icSigSampleICC(0x53494343), /* 'SICC' */
        icSigTheImagingFactory(0x33324254);  /* '32BT' */

        private int value;

        private icCmmSignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public enum icReferenceMediumGamutSignature {

        icSigPerceptualReferenceMediumGamut(0x70726d67);  /* 'prmg' */

        private int value;

        private icReferenceMediumGamutSignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    };

    public enum icColorimetricIntentImageStateSignature {

        icSigSceneColorimetryEstimates(0x73636F65), /* 'scoe' */
        icSigSceneAppearanceEstimates(0x73617065), /* 'sape' */
        icSigFocalPlaneColorimetryEstimates(0x66706365), /* 'fpce' */
        icSigReflectionHardcopyOriginalColorimetry(0x72686F63), /* 'rhoc' */
        icSigReflectionPrintOutputColorimetry(0x72706F63);  /* 'rpoc' */

        private int value;

        private icColorimetricIntentImageStateSignature(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public enum icMeasurementFlare {

        icFlare0(0x00000000), /* 0% flare */
        icFlare100(0x00000001);  /* 100% flare */

        private int value;

        private icMeasurementFlare(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public enum icMeasurementGeometry {

        icGeometryUnknown(0x00000000), /* Unknown geometry */
        icGeometry045or450(0x00000001), /* 0/45, 45/0 */
        icGeometry0dord0(0x00000002);  /* 0/d or d/0 */

        private int value;

        private icMeasurementGeometry(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public enum icRenderingIntent {

        icPerceptual,
        icRelativeColorimetric,
        icSaturation,
        icAbsoluteColorimetric,
    }

    public enum icSpotShape {

        icSpotShapeUnknown,
        icSpotShapePrinterDefault,
        icSpotShapeRound,
        icSpotShapeDiamond,
        icSpotShapeEllipse,
        icSpotShapeLine,
        icSpotShapeSquare,
        icSpotShapeCross
    }

    public enum icStandardObserver {

        icStdObsUnknown(0x00000000), /* Unknown observer */
        icStdObs1931TwoDegrees(0x00000001), /* 1931 two degrees */
        icStdObs1964TenDegrees(0x00000002); /* 1961 ten degrees */

        private int value;

        private icStandardObserver(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    }

    public enum icIlluminant {

        icIlluminantUnknown(0x00000000),
        icIlluminantD50(0x00000001),
        icIlluminantD65(0x00000002),
        icIlluminantD93(0x00000003),
        icIlluminantF2(0x00000004),
        icIlluminantD55(0x00000005),
        icIlluminantA(0x00000006),
        icIlluminantEquiPowerE(0x00000007), /* Equi-Power (E) */
        icIlluminantF8(0x00000008);
        private int value;

        private icIlluminant(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    };

    public enum icColorantEncoding {

        icColorantUnknown(0x0000), /* Unknown */
        icColorantITU(0x0001), /* ITU-R BT.709 */
        icColorantSMPTE(0x0002), /* SMPTE RP145-1994 */
        icColorantEBU(0x0003), /* EBU Tech.3213-E */
        icColorantP22(0x0004); /* P22 */

        private int value;

        private icColorantEncoding(int value) {
            this.value = value;
        }

        public int getValue() {
            return this.value;
        }
    };

    public static  class icDateTimeNumber {
        icDateTimeNumber(){
            
        }
        short year = 0;
        short month =0;
        short day = 0;
        short hours = 0;
        short minutes =0 ;
        short seconds = 0;
    }

    public static class icHeader {

        public icHeader() {
            date = new icDateTimeNumber();
            illuminant = new icXYZNumber();
        }


        int size;           /* Profile size in bytes */

        long cmmId;          /* CMM for this profile */

        int version;        /* Format version number */

        icProfileClassSignature deviceClass;    /* Type of profile */

        icColorSpaceSignature colorSpace;     /* Color space of data */

        icColorSpaceSignature pcs;            /* PCS, XYZ or Lab only */

        icDateTimeNumber date;           /* Date profile was created */

        int magic;          /* icMagicNumber */

        icPlatformSignature platform;       /* Primary Platform */

        int flags;          /* Various bit settings */

        int manufacturer;   /* Device manufacturer */

        int model;          /* Device model number */

        long attributes;     /* Device attributes */

        int renderingIntent;/* Rendering intent */

        icXYZNumber illuminant;     /* Profile illuminant */

        int creator;        /* Profile creator */

        icProfileID profileID;      /* Profile ID using RFC 1321 MD5 128bit fingerprinting */

        byte reserved[] = new byte[28];   /* Reserved for future use */

    }
    public static final int icMagicNumber = 0x61637370;  /* 'acsp' */

    public static final int icVersionNumber = 0x02000000;  /* 2.0, BCD */

    public static final int icVersionNumberV2_1 = 0x02100000;  /* 2.1, BCD */

    public static final int icVersionNumberV4 = 0x04000000;    /* 4.0, BCD */

    public static final int icVersionNumberV4_2 = 0x04200000;   /* 4.2, BCD */

}
